/*
 * Server.h
 *
 *  Created on: Nov 6, 2012
 *      Author: root
 */

#ifndef _SERVER_H_
#define _SERVER_H_

#include <functional>
#include <vector>
#include <map>

#include "Player.h"
#include "Packet.h"
#include "Handle.h"
#include "SystemAble.h"

class Server;

typedef SystemAble<Server> ServerSystem;

typedef std::shared_ptr<ServerSystem> ServerSystemPtr;


class Server
{
	std::vector<ServerSystemPtr> _systems;

	std::map<int,Handler *> _handles;

public:
	Server();
	virtual ~Server();

public:

	template<class T>
	void reg()
	{
		Reg<T,Server>(this);

		_systems.push_back(System<T>());
	}

	void init();


	void uninit();

public:

	void handle(const Packet & packet);

	void handle_player(const Handler * handler,const Packet & packet);

public:

	void insert_1(int id,const PacketHandle & func);

	void insert_2(int id,const PlayerPacketHandle & func);
};

#endif /* _SERVER_H_ */
